package com.dong.applicationcontext.event;

import org.springframework.context.ApplicationEvent;
import org.springframework.context.ApplicationEventPublisher;
import org.springframework.context.ApplicationEventPublisherAware;

import java.util.List;

/**
 * description
 *
 * @author Administrator 2021/09/06 20:04
 */
public class MyApplicationEventPublisherAware implements ApplicationEventPublisherAware {

    private List<String> blockedList;
    private ApplicationEventPublisher applicationEventPublisher;

    public void setBlockedList(List<String> blockedList) {
        this.blockedList = blockedList;
    }

    @Override
    public void setApplicationEventPublisher(ApplicationEventPublisher applicationEventPublisher) {
        this.applicationEventPublisher = applicationEventPublisher;
    }

    public void sendEmail(String address, String content) {
        if (blockedList.contains(address)) {
            System.out.println("发布事件");
            applicationEventPublisher.publishEvent(new BlockedListEvent(this, address, content));
            return;
        }
        // send email...
    }
}
